package ym.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import ym.mapper.FoodItemMapper;
import ym.pojo.FoodItem;

import java.util.List;

@DubboService
public class FoodItemServiceImpl implements FoodItemService {
    @Autowired
    private FoodItemMapper foodItemMapper;

    @Override
    public void add(FoodItem foodItem) {
        foodItemMapper.insert(foodItem);
    }

    @Override
    public void update(FoodItem foodItem) {
        foodItemMapper.updateById(foodItem);
    }

    @Override
    public void delete(Integer id) {
        foodItemMapper.deleteById(id);
    }

    @Override
    public FoodItem findById(Integer id) {
        return foodItemMapper.selectById(id);
    }

    @Override
    public List<FoodItem> findAll() {
        return foodItemMapper.selectList(null);
    }

    @Override
    public Page<FoodItem> search(String search, int page, int size) {
        QueryWrapper<FoodItem> queryWrapper = new QueryWrapper<>();
        if (search != null) {

        }
        return foodItemMapper.selectPage(new Page(page, size), queryWrapper);
    }

    @Override
    public Page<FoodItem> searchByMealId(Integer mealId, String search, int page, int size) {
        QueryWrapper<FoodItem> queryWrapper = new QueryWrapper<>();
        if (search != null) {
            queryWrapper.eq("mealId", mealId);
        } else {
            queryWrapper.eq("mealId", mealId);
        }
        return foodItemMapper.selectPage(new Page(page, size), queryWrapper);
    }

}
